<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>统计查询功能测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #555;
        }
        input[type="text"] {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
            box-sizing: border-box;
        }
        button {
            background-color: #007bff;
            color: white;
            padding: 12px 30px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            width: 100%;
        }
        button:hover {
            background-color: #0056b3;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            background-color: #e9f7ef;
            border-left: 5px solid #28a745;
            border-radius: 5px;
            display: none;
        }
        .error {
            background-color: #f8d7da;
            border-left: 5px solid #dc3545;
        }
        .loading {
            text-align: center;
            display: none;
        }
        .examples {
            margin-top: 30px;
            padding: 20px;
            background-color: #f8f9fa;
            border-radius: 5px;
        }
        .examples h3 {
            margin-top: 0;
        }
        .example-item {
            cursor: pointer;
            padding: 8px;
            margin: 5px 0;
            background-color: #e9ecef;
            border-radius: 3px;
        }
        .example-item:hover {
            background-color: #dee2e6;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>统计查询功能测试</h1>
        <div class="form-group">
            <label for="query">请输入您的统计查询问题：</label>
            <input type="text" id="query" placeholder="例如：查询专家总人数">
        </div>
        <button onclick="performQuery()">执行查询</button>
        
        <div class="loading" id="loading">
            <p>正在处理您的查询，请稍候...</p>
        </div>
        
        <div class="result" id="result"></div>
        
        <div class="examples">
            <h3>示例查询：</h3>
            <div class="example-item" onclick="setQuery('查询专家总人数')">查询专家总人数</div>
            <div class="example-item" onclick="setQuery('统计各品牌盾构机数量')">统计各品牌盾构机数量</div>
            <div class="example-item" onclick="setQuery('各单位专家数量统计')">各单位专家数量统计</div>
            <div class="example-item" onclick="setQuery('盾构专家人数')">盾构专家人数</div>
        </div>
    </div>

    <script>
        function setQuery(query) {
            document.getElementById('query').value = query;
        }

        function performQuery() {
            const query = document.getElementById('query').value.trim();
            const resultDiv = document.getElementById('result');
            const loadingDiv = document.getElementById('loading');
            
            if (!query) {
                alert('请输入查询问题');
                return;
            }
            
            // 显示加载状态
            loadingDiv.style.display = 'block';
            resultDiv.style.display = 'none';
            
            // 发送POST请求
            fetch('/stats/query', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    naturalLanguageQuery: query
                })
            })
            .then(response => response.json())
            .then(data => {
                loadingDiv.style.display = 'none';
                
                if (data.code === 200) {
                    resultDiv.innerHTML = '<h3>查询结果：</h3><pre>' + data.result + '</pre>';
                    resultDiv.classList.remove('error');
                } else {
                    resultDiv.innerHTML = '<h3>查询失败：</h3><p>' + data.message + '</p>';
                    resultDiv.classList.add('error');
                }
                
                resultDiv.style.display = 'block';
            })
            .catch(error => {
                loadingDiv.style.display = 'none';
                resultDiv.innerHTML = '<h3>请求失败：</h3><p>' + error.message + '</p>';
                resultDiv.classList.add('error');
                resultDiv.style.display = 'block';
            });
        }
        
        // 回车键触发查询
        document.getElementById('query').addEventListener('keypress', function(event) {
            if (event.key === 'Enter') {
                performQuery();
            }
        });
    </script>
</body>
</html>